SONARJAVA-6703 Implement new rule S9133 - #5862
Conversation
Detect hard-coded floating-point literals that approximate well-known mathematical constants (pi, e, sqrt(2), ln(2)) and suggest using the corresponding Math class constants or expressions instead.
|
❌ Ruling needs updating. A fix PR has been created: #5863 Please review and merge it into your branch. |
Ruling Diff SummaryDetected changes in 1 rule files: 0 issues removed, 18 issues added. S9133 (
|
Replace fixed relative tolerance with dynamic precision-based tolerance derived from the literal's significant digit count. Raise minimum significant digits from 3 to 4 to avoid false positives on common domain values like 0.693. Add test cases for underscore-separated literals, D/d suffixes, leading-dot literals, and zero value. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
4925f8b to
0c2cf07
Compare
Remove unreachable '-' and '+' handling from countSignificantDigits since Java literal tokens never contain sign characters. Add test cases for uppercase 'E' scientific notation, '0X' hex prefix, 'F' float suffix, and leading-dot noncompliant literal. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Code Review ✅ Approved 2 resolved / 2 findingsImplements rule S9133 to detect hard-coded floating-point approximations of mathematical constants, addressing the loose tolerance and normalize() edge case test coverage findings. ✅ 2 resolved✅ Edge Case: Loose tolerance may flag legitimate 3-digit domain values
✅ Quality: No tests for normalize() edge cases (underscores, D suffix, leading dot)
OptionsAuto-apply is off → Gitar will not commit updates to this branch. Comment with these commands to change the behavior for this request:
Was this helpful? React with 👍 / 👎 | Gitar |
|




Detect hard-coded floating-point literals that approximate well-known mathematical constants (pi, e, sqrt(2), ln(2)) and suggest using the corresponding Math class constants or expressions instead.
Part of